<!DOCTYPE html>
<html>
<head>
	<title>sort升降序</title>
</head>
<body>
<script type="text/javascript">

/* sort

	1. 传入函数，参数a,b必填
	2. 函数必须返回排序规则
	3. a-b升序		b-a降序

*/

let arra = ['a', 'bb', 'aaa', 'bab'];
arra.sort(function(a, b) {
	return a.length - b.length;		// 字母长度排序
})
console.log(arra)

let arrb = [12, 14, 2, 100, 4];
arrb.sort(function(a, b) {
	return a - b;
})
console.log(arrb)

</script>
</body>
</html>